package com.example.config;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnectFactory {

    private static final JedisPool JEDIS_POOL;

    static {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        // 最大连接数
        poolConfig.setMaxTotal(8);
        // 最大空闲连接数
        poolConfig.setMaxIdle(8);
        // 最小空闲连接数
        poolConfig.setMinIdle(0);
        // 获取连接时的最大等待毫秒数
        poolConfig.setMaxWaitMillis(1000);
        JEDIS_POOL = new JedisPool(poolConfig, "localhost", 6379);
    }

    public static Jedis getJedis() {
        return JEDIS_POOL.getResource();
    }
}
